//
//  HtmlController.m
//  OCDemo
//
//  Created by BH on 15/10/12.
//  Copyright © 2015年 baohan. All rights reserved.
//

#import "HtmlController.h"
#import "NSAttributedString+MLLabel.h"
#import "Masonry.h"

@interface HtmlController ()

@end

@implementation HtmlController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.top.equalTo(self.button.mas_bottom).offset(20);
        make.bottom.equalTo(self.view).offset(-10);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

-(Class)labelClass
{
    return [MLLinkLabel class];
}

-(NSInteger)resultCount
{
    return 1;
}

-(void)changeToResult:(NSInteger)result
{
    self.label.textColor = [UIColor redColor];
    self.label.font = [UIFont systemFontOfSize:14.f];
    self.label.numberOfLines = 0;
    self.label.textAlignment = NSTextAlignmentCenter;
    
    LABEL.dataDetectorTypes = MLDataDetectorTypeAll;
    [LABEL setDidClickLinkBlock:^(MLLink *link, NSString *linkText, MLLinkLabel *label) {
        
        SHOW_SIMPLE_TIPS(TIPS);
    }];
    
    NSString* html = @"<div style='font-size:14px'><center><b>黄莺儿</b></center><br/>"
    "<p>园林晴昼春谁主。<br/>暖律潜催，幽谷暄和，黄鹂翩翩，<font color='red'>乍迁芳树</font>。<br/>观露湿缕金衣，叶映如簧语。<br/>晓来枝上绵蛮，似把芳心、深意低诉。<sup>(1)</sup></p>"
    "<p>基本的html元素都支持，例如设置字体 <font face='Zapfino'>font</font>, 加粗"
    " <b>bold</b>, 斜体 <i>italics</i> 或者下划线 <u>underlined</u> <span style='color:red'>CSS</span> 等等。</p>"
    "<p>列表(注意里面的链接必须有:xxx//):<ul>"
    "<li>链接:&nbsp;<a href='https://github.com/molon/MLLabel'>MLLabel</a></li>"
    "<li>邮箱:&nbsp;<a href='mailto://dudl@qq.com'>我的邮箱</a></li>"
    "<li>电话:&nbsp;<a href='tel://13612341234'>假电话号码</a></li>"
    "</ul></p>"
    "当然这些还是需要使用者自己尝试下，最好不要随便拿html源码使用，这里只是为了更好的利用html生成可用的NSAttributedString，仅仅作为辅助来用。</div>";
    
    //注意，默认转成的html会给链接+上下划线属性，我们这里不要下划线
    LABEL.linkTextAttributes = @{NSForegroundColorAttributeName:kDefaultLinkColorForMLLinkLabel,NSUnderlineStyleAttributeName:@(0)};
    LABEL.activeLinkTextAttributes = @{NSForegroundColorAttributeName:kDefaultLinkColorForMLLinkLabel,NSBackgroundColorAttributeName:kDefaultActiveLinkBackgroundColorForMLLinkLabel,
                                       NSUnderlineStyleAttributeName:@(0)};
    
    self.label.attributedText = [NSAttributedString attributedStringWithHTML:html];
    
    self.label.frameWidth = self.view.frameWidth - 10.f*2;
    [self.label sizeToFit];
}

@end
